package se480.tracker.service;

import se480.tracker.event.EventFactory;
import se480.tracker.event.TrackerEvent;
import se480.tracker.processor.Processor;


/**
 * This will monitor the health of the Processor and Tracker instances
 * and notify if it finds it down.  The definition of "down" is left
 * up to the implementor.
 * 
 * @author mmichalak
 *
 */
public abstract class HealthMonitorServiceAbs {
	
	RegistrationService regSvc = null;
	Processor processor = null;
	
	/**
	 * This method is in charge of the health monitoring of the primary processor.
	 * This could be implemented to query and/or update to the primary proc.
	 * It could ensure a response comes back and/or within a certain time.
	 * 
	 * This method must invoke invokeFailover() when a failover is realized.
	 * 
	 * I leave this unimplemented since this is not used in the simulation.
	 * 
	 * @param proc
	 * @return false indicates the Processor is down
	 */
	public abstract boolean checkHealth(Processor proc);
	
	
	
	private void invokeFailover() {
		TrackerEvent ev = EventFactory.createEvent("FAIL " + processor.getId());
		regSvc.failOver(ev);
	}
}
